﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) [INCLUDE APACHE 2.0 AS AN OPTION.]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml.Serialization;
using System.Xml;
using Microsoft.PerformancePoint.Scorecards;
using ppscd;

namespace ppscd.Configuration
{
    [Serializable]
    [XmlRoot("PerformancePoint")]
    public class PerformancePointSettings
    {
        static PerformancePointSettings m_configuration;

        string m_siteCollectionPath = "/";
        string m_dataSourcesName = "Data Connections for PerformancePoint";
        string m_contentListName = "PerformancePoint Content";
        string m_webPath = "/BICenter";

        public PerformancePointSettings()
        {
            Locations = new List<Replacement>();
            DataSources = new DataSources();
            Dashboards = new Dashboards();
            Reports = new Reports();
        }

        [XmlAttribute]
        public string WorkspaceFile
        {
            get;
            set;
        }

        [XmlAttribute]
        public string DestinationServer
        {
            get;
            set;
        }

        [XmlAttribute]
        public string SiteCollectionPath
        {
            get;
            set;
        }

        public DataSources DataSources
        {
            get;
            set;
        }

        public Dashboards Dashboards
        {
            get;
            set;
        }

        [XmlElement]
        public Reports Reports
        {
            get;
            set;
        }

        [XmlElement(ElementName="Location")]
        public List<Replacement> Locations
        {
            get;
            set;
        }

        public static PerformancePointSettings Current
        {
            get
            {
                if (m_configuration == null)
                {
                    var serializer = new XmlSerializer(typeof(PerformancePointSettings));
                    m_configuration = serializer.Deserialize(new XmlTextReader("ppscd.settings")) as PerformancePointSettings;
                }

                return m_configuration;
            }
        }

        public string AuthoringServiceUrl
        {
            get
            {
                return UrlUtils.Combine(this.SiteCollectionUrl, "/_vti_bin/PPS/PPSAuthoringService.asmx");
            }
        }

        public IBIMonitoringAuthoring GetAuthoringService()
        {
            return BIMonitoringAuthoringServiceProxy.CreateInstance(this.AuthoringServiceUrl);
        }

        public string SiteCollectionUrl
        {
            get
            {
                return UrlUtils.Combine(PerformancePointSettings.Current.DestinationServer, this.SiteCollectionPath);
            }
        }

        //public string DataSourcesName
        //{
        //    get
        //    {
        //        return m_dataSourcesName;
        //    }
        //}

        //public string DataSourcesPath
        //{
        //    get
        //    {
        //        return UrlUtils.Combine("/", SiteCollectionPath, WebPath, DataSourcesName);
        //    }
        //}

        //public string WebPath
        //{
        //    get
        //    {
        //        return m_webPath;
        //    }

        //    set
        //    {
        //        m_webPath = value;
        //    }
        //}

        //public string ContentListPath
        //{
        //    get
        //    {
        //        return UrlUtils.Combine("/", SiteCollectionPath, WebPath, "/Lists/", ContentListName);
        //    }
        //}

        public string ContentListName
        {
            get
            {
                return m_contentListName;
            }
        }



        //public string WebUrl
        //{
        //    get
        //    {
        //        return UrlUtils.Combine(SiteCollectionUrl, WebPath);
        //    }
        //}
    }
}
